﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using DatingWebSite.DatingService;


namespace DatingWebSite.Pages
{
    public partial class MessageIdeas : System.Web.UI.Page
         

    {
        protected int ProfileId = 0;

        protected int TenantID = 1;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ProfileId = Convert.ToInt32(Session["MemberProfileID"]);
                TenantID = Convert.ToInt32(Session["TenentID"]);

                DatingService.DatingService obj = new DatingService.DatingService();
                DatingService.MessageIdea[] objMessageIdea = obj.MessageIdeaSelectAll(TenantID, "");

                chkBoxList.DataSource = objMessageIdea;
                chkBoxList.DataTextField = "Message";
                chkBoxList.DataValueField = "IdeaID";
                chkBoxList.DataBind();

                DatingService.MemberIdeaMessage[] objMemberMessage = obj.MemberIdeaMessageSelectAllByProfileID(ProfileId, TenantID, "");
                //DataSet ds = new DataSet();
                //ds = (DataSet)objMemberMessage;
                //chkBoxList.DataSource = objMemberMessage;
                // chkBoxList.DataValueField = "IdeaID";





                for (int i = 0; i < chkBoxList.Items.Count; i++)
                {
                    //for (int x = 0; x<objMemberMessage.Count ; x++)
                    //{
                    //    //if(chkBoxList.Items[i]==objMemberMessage.
                    //    //chkBoxList.Items[i].Selected = Convert.ToBoolean(dt.Rows[i]["IsSelected"]);
                    //}

                    for (int x = 0; x < (Convert.ToInt32(objMemberMessage.Length)); x++)
                    {
                        if (Convert.ToInt32(chkBoxList.Items[i].Value) == (objMemberMessage[x].IdeaID))
                            chkBoxList.Items[i].Selected = true;


                    }
                }
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            DatingService.DatingService obj = new DatingService.DatingService();
            obj.MemberIdeaMessageDeleteAllByProfileID(Convert.ToInt32(Session["MemberProfileID"]), 1, "");
            for (int i = 0; i < chkBoxList.Items.Count; i++)
            {
                if (chkBoxList.Items[i].Selected == true)
                {
                    MemberIdeaMessage memberIdeaMessage = new MemberIdeaMessage();
                    memberIdeaMessage.IdeaID = Convert.ToInt32(chkBoxList.Items[i].Value);
                    memberIdeaMessage.TenantID = 1;
                    memberIdeaMessage.ProfileID = Convert.ToInt32(Session["MemberProfileID"]);

                    obj.MemberIdeaMessageInsert(memberIdeaMessage, "");
                }
            }
        }
    }
}
